package Day01;

enum CarType {
    BMW,
    BENZ,
    AUDI
}

abstract class Car {
    abstract void run();
    abstract void boom();
}

class BMW extends Car {
    @Override
    void run() {
        System.out.println("BMW is running");
    }

    @Override
    void boom() {
        System.out.println("BMW is booming");
    }
}

class Benz extends Car {
    @Override
    void run() {
        System.out.println("Benz is running");
    }

    @Override
    void boom() {
        System.out.println("Benz is booming");
    }
}

class Audi extends Car {
    @Override
    void run() {
        System.out.println("Audi is running");
    }

    @Override
    void boom() {
        System.out.println("Audi is booming");
    }
}

class CarFactory {
    public static Car getCar(CarType carType){
        return switch (carType) {
            case BMW -> new BMW();
            case BENZ -> new Benz();
            case AUDI -> new Audi();
        };
    }
}

public class FactoryDemo {
    public static void main(String[] args) {
        Car car = CarFactory.getCar(CarType.BMW);
        car.run();
        car.boom();
        Car[] cars = new Car[3];
        for (int i = 0; i < cars.length; i++) {
            cars[i] = CarFactory.getCar(CarType.values()[i]);
        }
        for (Car car1 : cars) {
            if (car1 != null) {
                car1.run();
            }
            if (car1 != null) {
                car1.boom();
            }
        }
    }
}
